
import { checkSystemUpdate } from './api/system.js'
import { setUserInfo, getUserInfo } from './utils/storage.js'

App({
  onLaunch: function () {
    //检查小程序更新
    checkSystemUpdate();
    wx.setInnerAudioOption({obeyMuteSwitch : false});
  },
  onHide: function () {

  },
  globalData: {
    // 授权登录后获取的用户基本信息
    userInfo: { // 测试用待修改
      // nickName: '汪元会',
      // avatarUrl: 'https://thirdwx.qlogo.cn/mmopen/vi_32/sw36m5OS67agMibBw1ulocBjr5Hmv0zOkylyq7HrG3UD2ERQ2ux9IrMT1v7AxTrCgFmMnnb9QKPFtLyR80picBFA/132',
      nickName: '',
      avatarUrl: '',
    },
    activityTitle: '',// 活动标题
    h5Url: '',// live h5地址
    isH5NeedRefresh: false,// live h5是否需要刷新
    nynRechargeIndex: 0, //索引 扭一扭充值列表的索引
    nynLuckyIndex: 0, //索引 扭一扭中奖列表的索引
    nynList: [],
    // 测试用待修改
   // nynList: [{code:"0",desc:"谢谢参与"},{code:"4",desc:"18元"},{code:"5",desc:"58.8元"},{code:"6",desc:"88.8元"},{code:"7",desc:"28.8元"},{code:"8",desc:"68.8元"},{code:"9",desc:"38.8元"},{code:"10",desc:"谢谢参与"}],
  },
  setUserInfo(paramObj) {
    if(paramObj) {
      this.globalData.userInfo.nickName = paramObj.nickName;
      this.globalData.userInfo.avatarUrl = paramObj.avatarUrl;
      setUserInfo({
        nickName: paramObj.nickName,
        avatarUrl: paramObj.avatarUrl,
      });
    } else {
      const stUserInfo = getUserInfo();
      this.globalData.userInfo.nickName = stUserInfo.nickName;
      this.globalData.userInfo.avatarUrl = stUserInfo.avatarUrl;
    }
  },
  setH5Url(url) {
    this.globalData.h5Url = url;
  },
  updateNynRechargeIndex() {
    this.globalData.nynRechargeIndex += 1;
  },
  updateNynLuckyIndex() {
    this.globalData.nynLuckyIndex += 1;
  },
})